//
//  FormsView.swift
//  DiDiRecycle
//
//  Created by abb on 16/7/17.
//  Copyright © 2016年 abb. All rights reserved.
//

import UIKit

class FormsView: UIView {
    /// 是否设置为星号密码
    var secureTextEntry:Bool = false {
        didSet {
            textField.secureTextEntry = secureTextEntry
        }
    }   
    /// 电话号码
    var phoneNumber: String?
    /// 区号
    var zoneCode: String = "86"
    /// 验证码
    var password: String?
    // 回调闭包
    var textFieldDidEndEditCallBack:(text:String)->()

    init(CallBack:(text:String)->()) {
        self.textFieldDidEndEditCallBack = CallBack
        super.init(frame: CGRectZero)
        setupUI()
    }
    
    private func setupUI() {
        // 添加子控件
        addSubview(btn)
        addSubview(sepLine)
        addSubview(textField)
        
        // 布局子控件
        btn.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.height.equalTo(self).multipliedBy(0.8)
            make.width.equalTo(self).multipliedBy(0.1)
            make.left.equalTo(self)
        }
        textField.snp_makeConstraints { (make) in
            make.left.equalTo(btn.snp_right).offset(5)
            make.centerY.equalTo(self)
            make.top.bottom.right.equalTo(self)
        }
        sepLine.snp_makeConstraints { (make) in
            make.top.equalTo(textField.snp_bottom)
            make.width.left.equalTo(textField)
            make.height.equalTo(0.5)
        }
        textField.delegate = self
        
    }
    
    // MARK: - 懒加载
    /// 按钮
    lazy var btn: UIButton = {
        let btn = UIButton()
        return btn
    }()
    /// 分割线
    private lazy var sepLine :UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.blackColor()
        return view
    }()
    /// 文本框
    lazy var textField: UITextField = UITextField.creatTextField()
    
     required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
// MARK: - UITextFieldDelegate
extension FormsView:UITextFieldDelegate {
    func textFieldDidEndEditing(textField: UITextField) {
        if textField.text == "" || textField.text == nil {
            return
        }
        textFieldDidEndEditCallBack(text: textField.text!)
    }
    
}
